#include "comHandler.h"
#include <string.h>
#include <WProgram.h>

#define RED 4
#define GREEN 5
#define BLUE 6

int interpretCommand(char *input){
    if(strncmp(input, "LED.COL",7) == 0){
      return COM_LED_COL;
    }
    if(strncmp(input, "LED.INT",7) == 0){
      return COM_LED_INT;
    }
    if(strncmp(input, "POS.POS",7) == 0){
      return COM_POS_POS;
    }
    if(strncmp(input, "POS.DIV",7) == 0){
      return COM_POS_DIV;
    }
    if(strncmp(input, "GET.PRF.NAME",12) == 0){
      return COM_GET_PRF_NAME;
    }
    if(strncmp(input, "GET.CMDS",8) == 0){
      return COM_GET_CMDS;
    }
    if(strncmp(input, "GET.CONF",8) == 0){
      return COM_GET_CONF;
    }
    
    return COM_ERR;

}

int comLedCol(char *input){
    
    char temp[4];
    int red ,green, blue;
    if(strncmp(input, "LED.COL.STOP",12) == 0){
      return COM_LED_COL_END;
    }
    else{      
      strncpy(temp, input, 3);
      temp[3] = '\0';
      red = atoi(temp);
      strncpy(temp, &input[3], 3);
      temp[3] = '\0';
      green = atoi(temp);
      strncpy(temp, &input[6], 3);
      temp[3] = '\0';
      blue = atoi(temp);
      if(red >=0 && red <=255 && green >=0 && green <=255 && blue >=0 && blue <=255){
        analogWrite(RED, red);
        analogWrite(GREEN, green);
        analogWrite(BLUE, blue);
        return COM_OK;
      }
      else{
        return COM_ERR;
      }
    }

}
int comLedInt(char *input);
int comPosPos(char *input);
int comPosDiv(char *input);
